if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].sp_ReportLoiNhuan_LoiNhuanHoaDon') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].sp_ReportLoiNhuan_LoiNhuanHoaDon
go
create proc sp_ReportLoiNhuan_LoiNhuanHoaDon
@Ma_phieu_nhap_xuat  int 
as
begin
		select	A.Ki_hieu,
				b.So_luong,
				C.Ten as TenHangHoa,
				C.Gia_Nhap,
				C.Gia_ban_le,
				C.Gia_ban_si,
				(C.Gia_ban_le*b.So_luong)-(C.Gia_Nhap*b.So_luong) as LoiNhuan,
				(C.Gia_ban_le*b.So_luong)/((C.Gia_ban_le*b.So_luong)-(C.Gia_Nhap*b.So_luong))as PhanTram,
				c.Ma_hang
		from	phieunhapxuat as a,
				chitietnhapxuat as b ,
				hanghoa	as c
		where	a.id = b.ma_phieu_nhap_xuat
			and	b.ma_hang_hoa = c.id
			and a.id = @Ma_phieu_nhap_xuat	
end